import service from "@/server/serviceIndex";
import { useUseStore } from "@/stores/user";

// 根据用户Id查找用户账户表的积分余额和pi币余额
export const getInfoAPI = (uid) => {
    return service({
        method: "post",
        url: `/pipayshopapi/account-info/selectAccountById/${uid}`,
    });
};

// 获取用户信息方法
export const getUserInfoAPI = (uid) => {
    return service({
        method: "get",
        url: `/pipayshopapi/user-info/selectUserInfoByUid/${uid}`,
    });
};

// 根据用户id查询它的网店id
export const getItemIdByUserIdAPI = (userId) => {
    return service({
        method: "get",
        url: `/pipayshopapi/user-info/getItemIdByUserId/${userId}`,
    });
};

// 根据用户Id判断用户能绑定实体店的数量余额
export const getShopBalancedAPI = (uid) => {
    return service({
        method: "get",
        url: `/pipayshopapi/user-info/shopBalance/${uid}`,
    });
};

/**
 * 交易所接口
 */

// 发布交易
export const publishTradition = (token) => {
    return service({
        method: "post",
        url: `/pipayshopapi/account-info/publishTradition?token=${token}`,
    });
};

// 获取全部交易列表
export const getTraditionList = ({ typeId, page, limit, piName }) => {
    return service({
        method: "get",
        url: `/pipayshopapi/account-info/selectTraditionList/${typeId}/${page}/${limit}?piName=` + piName,
    });
};

// 获取用户交易列表
export const selectTradinyOrderByUid = (token) => {
    return service({
        method: "get",
        url: `/pipayshopapi/account-info/selectTradinyOrderByUid?token=${token}`,
    });
};

// 获取交易详情
export const getTraditionDetail = (tradinId) => {
    return service({
        method: "get",
        url: `/pipayshopapi/account-info/selectTraditionDetail/${tradinId}`,
    });
};

// 交易双方获取交易详情
export const getDealDetail = (orderId) => {
    return service({
        method: "get",
        url: `/pipayshopapi/account-info/selectTradinOrderDetail/${orderId}`,
    });
};

// 生成订单
export const generateTradeOrder = (tradinId,buyerId) => {
    return service({
        method: "post",
        url: `/pipayshopapi/account-info/generateTradeOrder/${tradinId}/${buyerId}`,   
    });
};

// 提交转积分
export const upLoadPointBalance = (token) => {
    return service({
        method: "post",
        url: `/pipayshopapi/account-info/upLoadPointBalance/${token}`,
    });
};

// 提交pi币转账凭证
export const upLoadImg = (token, data) => {
    return service({
        method: "post",
        url: `/pipayshopapi/account-info/upLoadImg/${token}`,
        headers: { "Content-Type": "multipart/form-data" },
        data,
    });
};

// 完成交易接口
export const confirmTransaction = (token) => {
    return service({
        method: "post",
        url: `/pipayshopapi/account-info/confirmTransaction/${token}`,
    });
};

// 首次注册pi账号登录后，强制要求其设置一个账号密码
export const insertRegisterData = (params) => {
    return service({
        method: "post",
        url: `/pipayshopapi/user-info/insertRegisterData`,
        params,
    });
};

// 获取验证码
export const checkCode = () => {
    return service({
        method: "get",
        url: `/pipayshopapi/user-info/checkCode`,
        responseType: "arraybuffer", //或者是blob
    });
};

// 外部登录
export const userRegister = (params, sessionId) => {
    return service({
        method: "post",
        url: `/pipayshopapi/user-info/userRegister`,
        params,
        headers: {
            sessionId,
        },
    });
};

// 获取汇率
export const selectAllTradinRate = () => {
    return service({
        method: "get",
        url: `/pipayshopapi/account-info/selectAllTradinRate`,
    });
};
//根据用户名查交易信息
// export const selectTraditionList = (typeId, page, limit, piName) => {
//     return service({
//         method: "GET",
//         url: `/pipayshopapi/account-info/selectTraditionListByPiName/${typeId}/${page}/${limit}/${piName}`,
//     })
// }

//获取用户未完成的订单数量
export const countOderApi=()=>{
    return service({
        method:"POST",
        url:"/pipayshopapi/account-info/api/countOrder?uid="+useUseStore().userId
    })
};

//取消交易订单
export const cancelTraditionAPI=(tradinId,publisherUid)=>{
    return service({
        method:"PUT",
        url:`/pipayshopapi/account-info/cancelTradition/${tradinId}/${publisherUid}`
    })
}

//上传支付二维码
